#ifndef LCD_H
#define LCD_H
#include "defines.h"
#include <inttypes.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include "spi.h"

#define LCD_PORT 	PORTB
#define LCD_PIN		PINB
#define LCD_DDR		DDRB

#define LCD_A0		PB3

#define LCD_DISPLAY_ON (0xAF)
#define LCD_DISPLAY_OFF (0xAE)

#define LCD_DISPLAY_ALL_POINTS_NORMAL (0xA4)
#define LCD_DISPLAY_ALL_POINTS_ON (0xA5)

#define LCD_END (0xEE)
#define LCD_RESET (0xE2)
#define LCD_NOP (0xE3)

#define LCD_BIAS_SET_19 (0xA2)
#define LCD_BIAS_SET_17 (0xA3)

#define LCD_ADC_SET_NORMAL (0xA0)
#define LCD_ADC_SET_REVERSE (0xA1)

#define LCD_DISPLAY_NORMAL (0xA6)
#define LCD_DISPLAY_REVERSE (0xA7)

#define LCD_COMMON_NORMAL (0xC0)
#define LCD_COMMON_REVERSE (0xC8)

#define LCD_DISPLAY_LINE_0 (0x40)

#define LCD_ELECTRONIC_SET (0x81)
#define LCD_POWER_SET_ALL_ON (0x2F)

#define LCD_READ_MODIFY_WRITE (0xE0)

#define LCD_INSTRUCTION_MODE() (LCD_PORT &= ~(1<<LCD_A0))
#define LCD_DATA_MODE() (LCD_PORT |= (1<<LCD_A0))


void lcd_init(void);

void lcd_command(uint8_t command);
void lcd_write_data(uint8_t data);
void lcd_select_line(uint8_t page);
void lcd_select_column(uint8_t column);
void lcd_clear_display(void);
void lcd_clear_command_line(void);
void lcd_refresh(void);
int8_t lcd_write_P(uint8_t line, char *c);
int8_t lcd_write(uint8_t line, char *c);
void lcd_write_char(char c);

#endif
